- merge_request = local_assigns.fetch(:merge_request, nil)
- project = local_assigns.fetch(:project) { merge_request&.project }
- ref = local_assigns.fetch(:ref) { merge_request&.source_branch }
- can_update_merge_request = can?(current_user, :update_merge_request, @merge_request)

- commits = @commits&.map { |commit| commit.present(current_user: current_user) }
- context_commits = @context_commits&.map { |commit| commit.present(current_user: current_user) }
- hidden = @hidden_commit_count

- commits.chunk { |commit| local_committed_date(commit, current_user) }.each do |day, daily_commits|
  %li.js-commit-header.gl-py-2.gl-border-b{ data: { day: day } }
    %span.day.font-weight-bold= l(day, format: '%b %d, %Y')

  %li.commits-row.gl-mb-6{ data: { day: day } }
    %ul.content-list.commit-list.flex-list
      - if Feature.enabled?(:cached_commits, project)
        = render partial: 'projects/commits/commit', collection: daily_commits, locals: { project: project, ref: ref, merge_request: merge_request }, cached: ->(commit) { commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) }
      - else
        = render partial: 'projects/commits/commit', collection: daily_commits, locals: { project: project, ref: ref, merge_request: merge_request }

- if context_commits.present?
  %li.js-commit-header.gl-py-2.gl-border-b
    %span.font-weight-bold= n_("%d previously merged commit", "%d previously merged commits", context_commits.count) % context_commits.count
    - if can_update_merge_request
      = render Pajamas::ButtonComponent.new(button_options: { class: 'gl-ml-3 add-review-item-modal-trigger', data: { context_commits_empty: 'false' } }) do
        = _('Add/remove')

  %li.commits-row.gl-mb-6
    %ul.content-list.commit-list.flex-list
      - if Feature.enabled?(:cached_commits, project)
        = render partial: 'projects/commits/commit', collection: context_commits, locals: { project: project, ref: ref, merge_request: merge_request }, cached: ->(commit) { commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) }
      - else
        = render partial: 'projects/commits/commit', collection: context_commits, locals: { project: project, ref: ref, merge_request: merge_request }

- if hidden > 0 && !@merge_request
  %li
    = render Pajamas::AlertComponent.new(variant: :warning,
      dismissible: false) do |c|
      - c.with_body do
        = n_('%s additional commit has been omitted to prevent performance issues.', '%s additional commits have been omitted to prevent performance issues.', hidden) % number_with_delimiter(hidden)

- if can_update_merge_request && context_commits&.empty? && !(defined?(@next_page) && @next_page)
  .add-review-item-modal-trigger{ data: { context_commits_empty: 'true' } }

- if commits.size == 0 && context_commits.nil?
  .commits-empty.gl-mt-6
    .svg-content.svg-150
      = image_tag('illustrations/empty-state/empty-search-md.svg')
    %h4
      = _('Your search didn\'t match any commits.')
    %p
      = _('Try changing or removing filters.')
